package io.closes.Utils;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

public class ValidateUtil {

    public static void checkListNotNull(List<?> param) {
        if(Objects.isNull(param) || param.isEmpty())
            throw new IllegalArgumentException("Illegal params, param: " + param);
    }

    public static void checkAnyNotNull(Object... params) {   //都为null
        if (Objects.nonNull(params)){
            for(Object it : params) {
                if(it != null)
                    return;
            }
        }
        throw new IllegalArgumentException("Illegal params, params: " + params);
    }
    public static void checkAllNotNull(Object... params) {
        if (Objects.isNull(params)){
            throw new IllegalArgumentException("Illegal params, params is null");
        }
        for(Object it : params) {
            if(it == null)
                throw new IllegalArgumentException("Illegal params, params: " + it);
        }
    }
    public static void checkNotNull(Object param) {
        if(Objects.isNull(param))
            throw new IllegalArgumentException("Illegal params, param: " + param);
    }

    public static Object checkWithDefault(Object param, Object defaultValue) {
        if(Objects.isNull(param))
            return defaultValue;
        return param;
    }

    static void checkStringAllNotEmpty(String...params){
        if (Objects.isNull(params)){
            throw new IllegalArgumentException("Illegal params , params: " + params);
        }
        for (String it : params) {
            if (StringUtils.isEmpty(it)){
                throw new IllegalArgumentException("Illegal params , params: " + params);
            }
        }
    }

    static void checkAllNotNullWithString(Object... params) {
        if (Objects.isNull(params)){
            throw new IllegalArgumentException("Illegal params, params：" + params);
        }
        for(Object it : params) {
            if ( Objects.isNull(it) ){
                throw new IllegalArgumentException("Illegal params, params: " + params);
            }else {
                if ( ("String").equals(it.getClass().getSimpleName()) && StringUtils.isEmpty(String.valueOf(it))){
                    throw new IllegalArgumentException("Illegal params, params: " + params);
                }
            }
        }
    }
}
